package org.com.wareon.videoServer;


import javax.media.*;
import javax.media.format.AudioFormat;

public class RTPClient implements ControllerListener, Runnable {

	Player p;
	MediaLocator src;

	public static void main(String[] args) {
		RTPClient rtp = new RTPClient("192.168.0.103");
		Thread t = new Thread(rtp);
		t.start();
	}

	public RTPClient(String ip) {
		String srcUrl = "rtp://" + ip + ":40401/audio/1";
		System.out.println(srcUrl);
		DataSink sink;
		src = new MediaLocator(srcUrl);
	}

	public void run() {
		try {

			Format input1 = new AudioFormat(AudioFormat.MPEGLAYER3);
			Format input2 = new AudioFormat(AudioFormat.MPEG);
			Format output = new AudioFormat(AudioFormat.LINEAR);
			PlugInManager.addPlugIn(
				"com.sun.media.codec.audio.mp3.JavaDecoder",
				new Format[]{input1, input2},
				new Format[]{output},
				PlugInManager.CODEC
			);

			p = Manager.createPlayer(src);
			p.addControllerListener(this);
			p.start();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public synchronized void controllerUpdate(ControllerEvent evt) {
		if (evt instanceof EndOfMediaEvent) {
			System.exit(0);
		} else {
			System.out.println(evt.toString());
		}
	}
}